package cn.gzten.lambda.runtime.logging;

import java.io.IOException;

public class LambdaLoggerImpl implements MyLambdaLogger {
    @Override
    public void log(String message) {
        System.out.println(message);
    }

    @Override
    public void log(byte[] message) {
        try {
            System.out.write(message);
        } catch (IOException e) {
            throw new RuntimeException("Error while writing out the log", e);
        }
    }

    @Override
    public void log(String messageTemplate, Object... args) {
        if (args.length > 0) {
            messageTemplate = messageTemplate.replaceAll("\\{\\s*\\}", "%s");
            this.log(String.format(messageTemplate, args));
        } else {
            this.log(messageTemplate);
        }
    }
}
